$(function(){  
    $(".list_table").colResizable({
      liveDrag:true,
      gripInnerHtml:"<div class='grip'></div>", 
      draggingClass:"dragging", 
      minWidth:30
    }); 
    $("form").submit(function(event) {
        $re = /^\d+(\.\d+)?$/;
        $good_name = $("#good_name").val();
        if($("#receiver").val()==""){
          alert("请填写收货人");
          $("#receiver").focus();
          return false;
        }

        if($("#receive_time").val()==""){
          alert("请选择时间");
          return false;
        }
        if($("#NO").val()==""){
          alert("请填写单号");
          $("#NO").focus();
          return false;
        }
        if($("#good_name").val()==""){
          alert("请选择品名");
          $("#good_name").focus();
          return false;
        }

        if($("#level").val()==""){
          alert("等级不能为空");
          $("#level").focus();
          return false;
        }

        if($("#num").val()==""){
          alert("数量不能为空");
          $("#num").focus();
          return false;
        }else{
          $num = $("#num").val();
          if(!$re.test($num)){
            $num = $("#num").val();
            alert("数量请输入合法的数据");
            $("#num").attr("value","");
            $("#num").focus();
            return false;
          }
        }
        if($good_name=="1"){
          $re = /^\d+(\.\d+)?$/;
          if($("#weight").val()==""){
            alert("重量不能为空");
            $("#weight").focus();
            return false;
          }else{
            $weight = $("#weight").val();
            if(!$re.test($weight)){
              alert("重量请输入合法的数据");
              $("#weight").attr("value","");
              $("#weight").focus();
              return false;
            }
          }
        }
        if($("#unit_price").val()==""){
          alert("单价不能为空");
          $("#unit_price").focus();
          return false;
        }else{
          $unit_price = $("#unit_price").val();
          if(!$re.test($unit_price)){
            alert("单价请输入合法的数据");
            $("#unit_price").attr("value","");
            $("#unit_price").focus();
            return false;
          }
        }
        return true;
   });
  
  $("#weight").blur(function(){
    $good_name = $("#good_name").val();
    $unit = $("#unit_price").val();
    if($good_name==""){
      alert("请先选择品名");
      return false;
    }
    if($good_name=="1"){
      $re = /^\d+(\.\d+)?$/;
      if($("#weight").val()==""){
        alert("重量不能为空");
        $("#weight").focus();
        return false;
      }else{
        $weight = $("#weight").val();
        if(!$re.test($weight)){
          alert("重量请输入合法的数据");
          $("#weight").attr("value","");
          $("#weight").focus();
          return false;
        }
      }
      $weight = $("#weight").val();
      $total = Math.round($unit*$weight*100)/100;
      $("#total_price").attr("value",$total);
      $("#total_price").attr("readonly",true);
      $("#total_price").css("background", "#FFE1FF");
    }
  
  });
  $("#unit_price").blur(function(){
      $re = /^\d+(\.\d+)?$/;
     
      if($("#unit_price").val()==""){
        alert("单价不能为空");
        $("#unit_price").focus();
        return false;
      }else{
        $unit_price = $("#unit_price").val();
        if(!$re.test($unit_price)){
          alert("单价请输入合法的数据");
          $("#unit_price").attr("value","");
          $("#unit_price").focus();
          return false;
        }
      }
      $good_name = $("#good_name").val();
      if($good_name==""){
        alert("请选择品名");
        return false;
      }
      if($good_name=="1"){
        $unit = $("#unit_price").val();
        $weight = $("#weight").val();
        $total = Math.round($unit*$weight*100)/100;
        $("#total_price").attr("value",$total);
        $("#total_price").attr("readonly",true);
        $("#total_price").css("background", "#FFE1FF");
      }else{
        $unit = $("#unit_price").val();
        $num = $("#num").val();
        $total = Math.round($unit*$num*100)/100;
        $("#total_price").attr("value",$total);
        $("#total_price").attr("readonly",true);
        $("#total_price").css("background", "#FFE1FF");
      }  
      
    });
  $("#num").blur(function(){
    $good_name = $("#good_name").val();
    $unit = $("#unit_price").val();
    if($good_name==""){
      alert("请先选择品名");
      return false;
    }
    if($good_name!="1"){
      $re = /^\d+(\.\d+)?$/;
      if($("#num").val()==""){
        alert("数量不能为空");
        $("#num").focus();
        return false;
      }else{
        $num = $("#num").val();
        if(!$re.test($num)){
          alert("数量请输入合法的数据");
          $("#num").attr("value","");
          $("#num").focus();
          return false;
        }
      }
      $num = $("#num").val();
      $total = Math.round($unit*$num*100)/100;
      $("#total_price").attr("value",$total);
      $("#total_price").attr("readonly",true);
      $("#total_price").css("background", "#FFE1FF");
    }
  
  });
  

});
